package com.eurobcoin.helper;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.eurobcoin.dao.mapper.StaticTextMapper;
import com.eurobcoin.dao.model.StaticText;
import com.eurobcoin.dao.model.StaticTextExample;
import com.eurobcoin.dao.model.StaticTextExample.Criteria;

public class TextsHelper {

	public static final String TXT_LBL_REG_USR_EMAIL_SUBJECT = "register_user_email_subject";
	public static final String TXT_LBL_REG_USR_EMAIL_BODY = "register_user_email_body";
	public static final String TXT_LBL_REG_USR_CONFIRM_URL = "register_user_confirm_url";
	
	public static final String TXT_LBL_INV_USR_EMAIL_SUBJECT = "invitation_email_subject";
	public static final String TXT_LBL_INV_USR_EMAIL_BODY = "invitation_email_body";
	public static final String TXT_LBL_INV_USR_URL = "invitation_url";
	
	public static String getStaticText(SqlSession sqlSession, String textLabel, String lang) {
		
		StaticTextMapper mapper = sqlSession.getMapper(StaticTextMapper.class);
		StaticTextExample example = new StaticTextExample();
		Criteria criteria = example.createCriteria();
		criteria.andTxt_labelEqualTo(textLabel);
		criteria.andTxt_langEqualTo(lang);
		
		List<StaticText> list = mapper.selectByExample(example);
		
		String ret = "";
		
		if(list.size() > 0) {
			ret = list.get(0).getTxt_content();
		}
		
		return ret;
	}
	
	public static String extractClassName(String canonical) {
		int index = canonical.lastIndexOf(".");
		String ret = canonical.substring(index + 1);
		return ret;
	}
	
}
